package abel.wlmr.model.type;

import java.util.HashMap;
import java.util.Map;

public enum UserTopCategory {
    WaterFactory(21),
    WaterPipe(22),
    WaterPressStat(23),
    WaterInd(24),
    WaterResident(25),
    WaterReserved(40);

    private short value;

    private static Map<Short, UserTopCategory> catList = new HashMap<>();

    static {
        for (UserTopCategory c : UserTopCategory.values()) {
            catList.put(c.value, c);
        }
    }

    private UserTopCategory(int v) {
        this.value = (short) v;
    }

    /**
     * Find user top category by value. May return null if value out of [21,40].
     * 
     * @param v
     * @return
     */
    public static UserTopCategory findCatByValue(short v) {
        if (v < 21 || v > 40) {
            return null;
        }

        if (catList.containsKey(v)) {
            return catList.get(v);
        } else {
            WaterReserved.value = v;
            return UserTopCategory.WaterReserved;
        }
    }

    /**
     * @return the value
     */
    public short getValue() {
        return value;
    }
}
